package org.liveboardgames.agricola.control.delegates.action.processor
{
    import org.liveboardgames.agricola.control.delegates.helper.GameHelper;
    import org.liveboardgames.agricola.model.AgricolaModelLocator;
    import org.liveboardgames.agricola.model.PopupModel;
    import org.liveboardgames.agricola.vo.action.Action;
    import org.liveboardgames.agricola.vo.farm.Farm;
    import org.liveboardgames.agricola.vo.farm.FarmElement;
    import org.liveboardgames.agricola.vo.player.Player;
    import org.liveboardgames.common.dictionary.collections.IMap;
    
    public class RoomActionProcessor extends ActionProcessor
    {
        private var cost:IMap;
        
        private var player:Player;
        
        public function RoomActionProcessor(action:Action)
        {
            super(action);
        }
        
        /** Assumes the check has already been done beforehand. */
        override public function execute():void
        {
            player = action.target as Player;
            
            // Compute the number of rooms the player can afford
            cost = action.cost;
            var farm:Farm = player.farm;
            var roomType:String = FarmElement.getRoomMaterial(farm.getTileAt(0).farmElement);
            var numberOfRooms:int = GameHelper.getNbAffordableItems(farm, cost);
            
            AgricolaModelLocator.getInstance().popups.currentActionPopupIndex = PopupModel.POPUP_BUILD_ROOM_INDEX;
            AgricolaModelLocator.getInstance().popups.numberOfRoomsToBuild = numberOfRooms;
            AgricolaModelLocator.getInstance().popups.materialOfRoomToBuild = roomType;
            AgricolaModelLocator.getInstance().popups.cost = cost;
        }
    }
}